{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# SAKSHAT提供的蜂鸣器使用方法\n",
    "当前SAKSHAT为我们提供的方法参考：http://wiki.nxez.com/saks:sdk:libraries:buzzer\n",
    "\n",
    "Buzzer\n",
    "\n",
    "有源蜂鸣器类，控制蜂鸣器对象发出声音。\n",
    "方法\n",
    "\n",
    "__init__(self, pin, real_true = GPIO.HIGH)\n",
    "\n",
    "初始化对象，设置蜂鸣器引脚和触发电平（高电平或低电平触发）。\n",
    "\n",
    "is_on(self)\n",
    "\n",
    "返回当前蜂鸣器工作状态。\n",
    "\n",
    "on(self)\n",
    "\n",
    "设置蜂鸣器开始工作。\n",
    "\n",
    "off(self)\n",
    "\n",
    "设置蜂鸣器停止工作。\n",
    "\n",
    "beep(self, seconds)\n",
    "\n",
    "设置蜂鸣器鸣叫 seconds 的时间。seconds 为毫秒时间。\n",
    "\n",
    "beepAction(self, secs, sleepsecs, times)\n",
    "\n",
    "设置蜂鸣器鸣叫 seconds 的时间，并间隔 sleepsecs 的时间再次鸣叫，如此周而复始 times 次。seconds 为毫秒时间。sleepsecs 为毫秒时间。times 为次数。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#让蜂鸣器一直响\n",
    "from sakshat import SAKSHAT\n",
    "from sakspins import SAKSPins as PINS\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        #Declare the SAKS Board\n",
    "        SAKS = SAKSHAT()\n",
    "        \n",
    "        #让蜂鸣器一直响\n",
    "        SAKS.buzzer.on()\n",
    "        \n",
    "    except KeyboardInterrupt:\n",
    "        print(\"任务被终止了\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#让蜂鸣器停止响\n",
    "from sakshat import SAKSHAT\n",
    "from sakspins import SAKSPins as PINS\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        #Declare the SAKS Board\n",
    "        SAKS = SAKSHAT()\n",
    "        \n",
    "        #让蜂鸣器一直响\n",
    "        SAKS.buzzer.off()\n",
    "        \n",
    "    except KeyboardInterrupt:\n",
    "        print(\"任务被终止了\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#返回当前蜂鸣器的状态\n",
    "import time\n",
    "from sakshat import SAKSHAT\n",
    "from sakspins import SAKSPins as PINS\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        #Declare the SAKS Board\n",
    "        SAKS = SAKSHAT()\n",
    "        \n",
    "        #让蜂鸣器一直响\n",
    "        SAKS.buzzer.on()\n",
    "        \n",
    "        #获取蜂鸣器状态\n",
    "        buzzer_status = SAKS.buzzer.is_on\n",
    "        \n",
    "        print(\"蜂鸣器响时，状态为：\" + str(buzzer_status))\n",
    "        \n",
    "        time.sleep(5)\n",
    "        \n",
    "        #让蜂鸣器停止响\n",
    "        SAKS.buzzer.off()\n",
    "        \n",
    "        #获取蜂鸣器状态\n",
    "        buzzer_status = SAKS.buzzer.is_on\n",
    "        \n",
    "        print(\"蜂鸣器不响时，状态为：\" + str(buzzer_status))\n",
    "        \n",
    "        time.sleep(5)\n",
    "        \n",
    "    except KeyboardInterrupt:\n",
    "        print(\"任务被终止了\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#让蜂鸣器只响5s\n",
    "from sakshat import SAKSHAT\n",
    "from sakspins import SAKSPins as PINS\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        #Declare the SAKS Board\n",
    "        SAKS = SAKSHAT()\n",
    "        \n",
    "        #让蜂鸣器只响5s\n",
    "        SAKS.buzzer.beep(5)\n",
    "        \n",
    "    except KeyboardInterrupt:\n",
    "        print(\"任务被终止了\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#播放出报警声音\n",
    "from sakshat import SAKSHAT\n",
    "from sakspins import SAKSPins as PINS\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        #Declare the SAKS Board\n",
    "        SAKS = SAKSHAT()\n",
    "        \n",
    "        #让蜂鸣器一次响1s，两次两次间隔2s，共响5次\n",
    "        SAKS.buzzer.beepAction(1, 2, 5)\n",
    "        \n",
    "    except KeyboardInterrupt:\n",
    "        print(\"任务被终止了\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#一直像闹钟一样响\n",
    "import time\n",
    "from sakshat import SAKSHAT\n",
    "from sakspins import SAKSPins as PINS\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        #Declare the SAKS Board\n",
    "        SAKS = SAKSHAT()\n",
    "        \n",
    "        while True:\n",
    "            #让蜂鸣器一直响\n",
    "            SAKS.buzzer.beepAction(0.01, 0.3, 2)\n",
    "            time.sleep(1)\n",
    "        \n",
    "    except KeyboardInterrupt:\n",
    "        print(\"任务被终止了\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
